var messageMode = "none";
var editId = 0;
var quoteId = 0;
	
	function bindReplyControls(){
		

		var board = $("#reply_board").val();
		var category = $("#reply_category").val();
		var topic = $("#reply_topic").val();
		var title = $("#reply_title").val();
		
		jQuery.each(jQuery.browser, function(i) {
											 
		  	if($.browser.msie){
				
				$('#reply_box').hide();
				$('.ui-overlay').hide();
		
				$('.reply_link_box').bind('click', function(){
					if($("#reply_box_active").val()==0){
						$.get('ajax/forum/getpostform.php', {topic_id: topic, board_id: board, category_id: category, topic_text:title }, function(data){
																																			 
							$('#reply_box_container').hide();
							$('#reply_box_container').html(data);
							$('#reply_box_container').show();
							
							messageMode = "reply";
							$('#reply_mode').html('Reply to topic:');
							$('#reply_title_box').val('Re: '+$('#topic_title').attr('title'))
							$('#reply_box').show();
							$('.ui-overlay').show();
							$('#reply_message_box').focus()
						});
						$("#reply_box_active").val(1)
					}
					
				});
	
				$('.edit_reply').bind('click', function(){
					messageMode = "edit";
					postId = $(this).attr('tt');
					editId = postId;
						$.get('ajax/forum/getpostform.php', {topic_id: topic, board_id: board, category_id: category, topic_text:title }, function(data){
																																			 
							$('#reply_box_container').hide();
							$('#reply_box_container').html(data);
							$('#reply_box_container').show();
					
							title = $('#post'+postId).attr('tt');
							$.get('ajax/forum/getpost.php', { postid: postId }, function(data){
								$('#reply_mode').html('Editing a post:');
								$('#reply_title_box').val(title)
								$('#reply_message_box').val(data)
								$('#reply_box').show();
								$('.ui-overlay').show();
								$('#reply_message_box').focus()
							})
						});
				});

				$('.quote_box').bind('click', function(){
					if($("#reply_box_active").val()==0){
						postId = $(this).attr('tt');
						userName = $(this).attr('dd');
						$.get('ajax/forum/getpostform.php', {topic_id: topic, board_id: board, category_id: category, topic_text:title }, function(data){
																																			 
							$('#reply_box_container').hide();
							$('#reply_box_container').html(data);
							$('#reply_box_container').show();

							messageMode = "quote";
							quoteId = postId;
							$('#reply_mode').html('Reply to topic (quoting):');
							$('#reply_title_box').val('Re: '+$('#topic_title').attr('title'))
							$('#reply_box').show();
							$('.ui-overlay').show();
							$.get('ajax/forum/getpost.php', { postid: postId }, function(data){
								$('#reply_message_box').val("[quote="+userName+"]"+data+"[/quote]")
							})
							$('#reply_message_box').focus();
						});
						$("#reply_box_active").val(1)
					}
				});

				$('.new_topic_box').bind('click', function(){
					$.get('ajax/forum/getpostform.php', {topic_id: '', board_id: board, category_id: category, topic_text:'' }, function(data){
						$('#reply_box_container').html(data);
						//alert(data);
						$('#reply_box_container').show();
						messageMode = "newtopic";
						$('#reply_mode').html('Making a new topic:');
						$('#reply_title_box').val('')
						$('#reply_box').show();
						$('.ui-overlay').show();
						$('#reply_title_box').focus()
					});			
					$("#reply_box_active").val(1)
				});
			
			} else {
							
				$('#reply_box').css({opacity: 0.0}).hide();
				$('.ui-overlay').css({opacity: 0.0}).hide();
		
				$('.reply_link_box').bind('click', function(){
					if($("#reply_box_active").val()==0){
						$.get('ajax/forum/getpostform.php', {topic_id: topic, board_id: board, category_id: category, topic_text:title }, function(data){
																																			 
							$('#reply_box_container').hide();
							$('#reply_box_container').html(data);
							$('#reply_box').css({opacity: 0.0}).hide();
							$('.ui-overlay').css({opacity: 0.0}).hide();
							$('#reply_box_container').show();
							
							messageMode = "reply";
							$('#reply_mode').html('Reply to topic:');
							$('#reply_title_box').val('Re: '+$('#topic_title').attr('title'))
							$('#reply_box').show();
							$('.ui-overlay').show();
							$('#reply_box').animate({opacity: 100}, 500, 'linear', function(){ });
							$('.ui-overlay').animate({opacity: 1.0}, 500, 'linear', function(){ });
							$('#reply_message_box').focus();
						});
						$("#reply_box_active").val(1)
					}
				});
				
				$('.edit_reply').bind('click', function(){
					if($("#reply_box_active").val()==0){						
						postId = $(this).attr('tt');
						editId = postId;

						$.get('ajax/forum/getpostform.php', {topic_id: topic, board_id: board, category_id: category, topic_text:title }, function(data){
																																			 
							$('#reply_box_container').hide();
							$('#reply_box_container').html(data);
							$('#reply_box').css({opacity: 0.0}).hide();
							$('.ui-overlay').css({opacity: 0.0}).hide();
							$('#reply_box_container').show();
							
							messageMode = "edit";
							title = $('#post'+postId).attr('tt');
							$.get('ajax/forum/getpost.php', { postid: postId }, function(data){
								$('#reply_mode').html('Editing a post:');
								$('#reply_title_box').val(title)
								$('#reply_message_box').val(data)
								$('#reply_box').show();
								$('.ui-overlay').show();
								$('#reply_box').animate({opacity: 1.0}, 500, 'linear', function(){ });
								$('.ui-overlay').animate({opacity: 1.0}, 500, 'linear', function(){ });
								$('#reply_message_box').focus()
							});
						});
						$("#reply_box_active").val(1)
					}
					
				});
				
				$('.quote_box').bind('click', function(){
					if($("#reply_box_active").val()==0){
						postId = $(this).attr('tt');
						userName = $(this).attr('dd');
						$.get('ajax/forum/getpostform.php', {topic_id: topic, board_id: board, category_id: category, topic_text:title }, function(data){
																																			 
							$('#reply_box_container').hide();
							$('#reply_box_container').html(data);
							$('#reply_box').css({opacity: 0.0}).hide();
							$('.ui-overlay').css({opacity: 0.0}).hide();
							$('#reply_box_container').show();

							messageMode = "reply";
							$('#reply_mode').html('Reply to topic:');
							$('#reply_title_box').val('Re: '+$('#topic_title').attr('title'))
							$('#reply_box').show();
							$('.ui-overlay').show();
							$('#reply_box').animate({opacity: 100}, 500, 'linear', function(){ });
							$('.ui-overlay').animate({opacity: 1.0}, 500, 'linear', function(){ });
							$.get('ajax/forum/getpost.php', { postid: postId }, function(data){
								$('#reply_message_box').val("[quote="+userName+"]"+data+"[/quote]")
							})
							$('#reply_message_box').focus();
						});
						$("#reply_box_active").val(1)
					}
				});
				
				$('.new_topic_box').bind('click', function(){
					if($("#reply_box_active").val()==0){
						$.get('ajax/forum/getpostform.php', {topic_id: '', board_id: board, category_id: category, topic_text:'' }, function(data){
																																			 
							$('#reply_box_container').hide();
							$('#reply_box_container').html(data);
							$('#reply_box').css({opacity: 0.0}).hide();
							$('.ui-overlay').css({opacity: 0.0}).hide();
							$('#reply_box_container').show();
							
							messageMode = "newtopic";
							$('#reply_mode').html('Making a new topic:');
							$('#reply_title_box').val('')
							$('#reply_box').show();
							$('.ui-overlay').show();
							$('#reply_box').animate({opacity: 1.0}, 500, 'linear', function(){ }).show();
							$('.ui-overlay').animate({opacity: 1.0}, 500, 'linear', function(){ }).show();
							$('#reply_title_box').focus()
						});
						$("#reply_box_active").val(1)
					}
				});
			}
		  	
			
		}); // end each browser

		
		
	}